<?php
/*
 * 商家的数据库操作类
 * @package    Db
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: d3b11f0cce921730b6e629f203e2b1e280715126 $
 */
defined('IN_IXDCW') or exit('Access Denied');
final class BusinessPictureDb extends CoreDb{
	public $_businessTable;
	public function __construct(){
		parent::__construct();
		$businessDb = Db('business');
		$this->_businessTable = $businessDb->tableName();
	}

	public function getByItemid($itemid) {
		$sql = "
			SELECT p.*
			FROM {$this->tableName()} p
			WHERE p.itemid={$itemid}";
		return $this->_db->getOne($sql);
	}

	public function deleteByItemid($itemid) {
		return $this->_db->query("delete from {$this->tableName()} where itemid=".$itemid);
	}

	/**
	 * 获取会员数量
	 * @param string $condition
	 * @return int
	 */
	public function getCount($condition = '') {
		$sqlMatchedNum = "
			SELECT COUNT(p.itemid) num
			FROM {$this->tableName()} p
			WHERE 1 ";
		if ($condition) $sqlMatchedNum .= $condition;
		return intval($this->_db->getVar($sqlMatchedNum, 'num'));
	}

	/**
	 * 获取列表
	 * @param string $condition
	 * @return array
	 */
	public function getList($condition = ''){
		$memberTable = DbMember::$table_name;
		$sqlList = "
			SELECT p.*, m.username, b.shopname
			FROM {$this->tableName()} p, {$memberTable} m, {$this->_businessTable} b
			WHERE m.userid=p.userid and b.userid=m.userid";
		if ($condition) $sqlList .= $condition;
		$lists = $this->_db->getAll($sqlList);
		return $lists;

	}
}